#include <iostream>
#include <set>
#include <map>
#include <string>
#include <utility>
using std::map;
using std::cout;
using std::endl;
using std::pair;
using std::string;
using std::set;

void test0(){
    string string1("hello");
    int num = 1;
    pair<int, string> pair1(num, string1);
    pair<int, string> pair2(10, "hello");
    cout << pair1.first << " " << pair1.second << endl;
    cout << pair2.first << " " << pair2.second << endl;
}

/**
 * set 插入
 */
void test1(){
    set<int> set1 = {1, 2, 3, 4, 5, 6, 7};

//    pair<set<int>::iterator, bool> ret = set1.insert(9);
//
//    if(ret.second){
//        printf("insert success\n");
//    } else{
//        printf("insert failed\n");
//    }

    set<int> set2 = {8, 3, 5};
    /* 插入多个元素 */
//    set1.insert(set2.begin(), set2.end());
//    for(auto& elem: set1){
//        cout << elem << endl;
//    }


//    int array[5] = {3, 2, 5, 8, 6};
//    set2.insert(array, array + 5);
//    for(auto& elem: set2){
//        cout << elem << " ";
//    }

//    set2.insert({1, 2, 5, 8, 0});
//    for(auto& elem: set2){
//        cout << elem << " ";
//    }
    set<int>::iterator it = set2.begin();
    it++;
    cout << *it << endl;
//    *it = 1;(不允许)
}
/**
 * map 的构造和操作
 */
void test2(){
    pair<int, string> pair1 = {7, "data"};
    map<int, string> map1 ={
            {1, "ls"},
            {2, "pwd"},
            {3, "get file"},
            pair1,/* 拷贝构造 */
            pair<int, string>(8, "mkdir"), /* 匿名 */
            std::make_pair(4, "put file")
    };

    /* 增强for循环遍历 */
    for(auto &elem:map1){
        cout << elem.second << endl;
    }

    /* 迭代器遍历 */
    for(map<int,string>::iterator it = map1.begin(); it != map1.end(); it++){
        cout << it->second << endl;
    }

}

/**
 * set的查找和插入
 */
void test3(){
    pair<int, string> pair1 = {7, "data"};
    map<int, string> map1 ={
            {1, "ls"},
            {2, "pwd"},
            {3, "get file"},
            pair1,/* 拷贝构造 */
            pair<int, string>(8, "mkdir"), /* 匿名 */
            std::make_pair(4, "put file")
    };

    pair<map<int,string>::iterator, bool> ret1 =  map1.insert(std::make_pair(1, "cat"));
    if(ret1.second){
        printf("insert ok\n");
    }else{
        printf("insert fail\n");
    }

    map1.insert({{11, "yum"}, {12, "snap"}, {13, "ll"}});



    if(map1.count(3)){
        printf("ok\n");
    } else{
        printf("fail\n");
    }

    /* 失败返回尾后迭代器 */
    map<int,string>::iterator ret2 = map1.find(6);
    if(ret2 != map1.end()){
        printf("ok\n");
    } else{
        printf("fail\n");
    }

}

void test4(){
    map<int, string> map1 ={
            {1, "ls"},
            {2, "pwd"},
            {3, "get file"},
            pair<int, string>(8, "mkdir"), /* 匿名 */
            std::make_pair(4, "put file")
    };

    map1[0] = "test";
    cout << map1[0] << endl;

}


void test5(){
    map<string,int> map = {
            {"fuck", 1},
            {"dick", 1},
            {"tit",  2}
    };
}

int main() {
    test4();
    return 0;
}
